<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input id="img" type="image" src="https://tse1-mm.cn.bing.net/th/id/R-C.2e2aaa3df72cac713ff0a8ab4c21240f?rik=fJuhJkG98S3y0Q&riu=http%3a%2f%2ffile.qqtouxiang.com%2fqinglv%2f2020-07-20%2f4f7a8d5656ca8202636fae359dbdaf85.jpeg&ehk=gBhFvA84l8Ashvql7FKoJ1eLfyjHV19COCgSZWcJ7hw%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1" />
		<button id="btn" type="button">点击下载图片</button>
		<script type="text/javascript">
			btn.onclick = function() {
				var x = new XMLHttpRequest();
				    x.open("GET", img.getAttribute('src'), true);
				    x.responseType = 'blob';
				    x.onload = function(e) {
				        var url = window.URL.createObjectURL(x.response)
				        var a = document.createElement('a');
				        a.href = url
				        a.download = ''
								console.log(a);
				        a.click()
				    }
				    x.send();
			}
			let files = ["https://tse1-mm.cn.bing.net/th/id/R-C.2e2aaa3df72cac713ff0a8ab4c21240f?rik=fJuhJkG98S3y0Q&riu=http%3a%2f%2ffile.qqtouxiang.com%2fqinglv%2f2020-07-20%2f4f7a8d5656ca8202636fae359dbdaf85.jpeg&ehk=gBhFvA84l8Ashvql7FKoJ1eLfyjHV19COCgSZWcJ7hw%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1", "http://localhost/upload/j8YGkmgedNwEXeVDXG9oPko1.jpeg", "http://localhost/upload/18UtX_b9LYOKZKeTHE4Mn5mZ.jpeg"];
			btn.onclick = function() {
				files.forEach(item => {
					var x = new XMLHttpRequest();
					    x.open("GET", item , true);
					    x.responseType = 'blob';
					    x.onload = function(res) {
					        var url = window.URL.createObjectURL(x.response)
					        var a = document.createElement('a');
									let e = document.createEvent('MouseEvents') // 创建鼠标事件对象
					        e.initEvent('click', false, false) // 初始化事件对象
									a.href = url
					        a.download = item + '.png'
									console.log(a);
					        a.click();
									a.dispatchEvent(e)
					    }
					    x.send();
				})
			}
		</script>
	</body>
</html>
